#ifndef INTRINSICCALIBRATION_H
#define INTRINSICCALIBRATION_H
#include <QtWidgets/QMainWindow>
#include "ui_intrinsiccalibration.h"
#include <SensorUtility/Sensor.h>
#include <QVector>
#include <QListWidgetItem>
#include "CheckBoard.h"
#include "DataPack.h"
#include <SensorUtility/SensorIntrinsic.h>


class IntrinsicCalibration : public QMainWindow
{
	Q_OBJECT

public:
	IntrinsicCalibration (QWidget* parent = 0);
	~IntrinsicCalibration ();

protected:
	virtual void closeEvent (QCloseEvent*);
	virtual void showEvent (QShowEvent*);

private:
	Ui::IntrinsicCalibrationClass ui;
	Sensor* _pSensor;
	int _curSensorItemIdx;
	bool _isOpened;
	QVector< QListWidgetItem* > _sensorItemPtrs;
	CheckBoard _checkBoard;
	enum Stage { IDLE, COLLECTING, SHOW_RESULT } _stage;
	QString _dataDir;
	QString _dataFile;
	std::vector< DataPack > _data;
	SensorIntrinsic _intrinsic;

	void openEvent ();
	void _switchToSensor (Sensor* pNewSensor);
	void _setToIdle ();
	void _startCollection ();
	void _collectAFrame ();
	void _calcAndValidate ();
	void _outputCalibrationResult ();

public slots:
	void handleSensorItemClicked (QListWidgetItem* pCurItem);
	void handleSensorItemClicked ();
	void handleNewFrame ();
	void handleNextStageClicked ();

	void updateTimerProgress ();
};

#endif // INTRINSICCALIBRATION_H
